package com.zeng.sys.filemd.servicemodule.vo;

import com.zeng.nicecore.convert.AbstractConvertor;
import com.zeng.nicecore.util.BeanUtil;
import com.zeng.nicecore.validation.ValidGroup;
import com.zeng.sys.filemd.servicemodule.entity.FileType;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Null;
import java.util.Date;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class FileTypeVo {
    //分类名称 例如 应用LOGO
    private String name;
    //分类标识 例如APP_LOGO
    private String flag;
    //文件类型限制
    private String typeLimit;
    //分类状态
    private String status;
    //大小限制
    private Long sizeLimit;

    @Null(groups = ValidGroup.add.class,message = "version must be empty when adding records ")
    private Integer version;

    @Null(groups = ValidGroup.add.class,message = "valid must be empty when adding records ")
    private Short valid;

    @Null(groups = ValidGroup.add.class,message = "code must be empty when adding records")
    @NotEmpty(groups = ValidGroup.update.class,message = "code must be excluded where update record ")
    private String code;

    @Null(groups = ValidGroup.add.class,message = "id must be empty when adding records")
    private Integer id;

    @Null(groups = ValidGroup.add.class,message = "updateDate must be empty when adding records")
    private Date updateDate;

    @Null(groups = ValidGroup.add.class,message = "insertDate must be empty when adding records")
    private Date insertDate;

    public FileType convertToFileType(){
        return new FileTypeVoConvertable().voToBean(this);
    }

    public static FileTypeVo convertToFileTypeVo(FileType fileType){
        return new FileTypeVoConvertable().beanToVo(fileType);
    }

    public static List<FileTypeVo> listFileTypeVo(List<FileType> fileTypes){
        return new FileTypeVoConvertable().toList(fileTypes);
    }

    public static List<FileType> listFileType(List<FileTypeVo> fileTypeVos){
        return new FileTypeVoConvertable().toBeanList(fileTypeVos);
    }

    private static class FileTypeVoConvertable implements AbstractConvertor<FileType, FileTypeVo> {

        @Override
        public FileTypeVo beanToVo(FileType fileType) {
            return BeanUtil.beanToVo(fileType, new FileTypeVo());
        }
    
        @Override
        public FileType voToBean(FileTypeVo fileTypeVo) {
            return BeanUtil.VoToBean(fileTypeVo, new FileType());
        }
    }
}